#include "InputManager.hpp"
#ifndef IPHONE 
#include "../../VisualStudio/stdafx.h"
#endif

using namespace Typhoon;

InputManager::InputManager() {
	Input left;
	left.Index = 0;
	left.Position = Vector2(0,0);
	left.Down = false;
	current.push_back(left);
	Input right;
	right.Index = 1;
	right.Position = Vector2(0,0);
	right.Down = false;
	current.push_back(right);
	previous = current;
}

InputManager::~InputManager() {
}

Vector2 InputManager::GetPosition(int index) {
	return current[0].Position;
}

#ifndef IPHONE

void InputManager::Update(void* input) {
    
	MSG* msg = (MSG*)input;
	
	switch (msg->message) {
	case WM_KEYDOWN: {

		switch (msg->wParam) 
		{ 
			case VK_LEFT: 
				{

					int g = 5;
					g++;
					break;
				}
		}

		}


		case WM_MOUSEMOVE: {

			// Retrieve mouse screen position
			int x=(short)LOWORD(msg->lParam);
			int y=(short)HIWORD(msg->lParam);

			current[0].Position = Vector2(x, y);
			current[1].Position = current[0].Position;

			// Check to see if the left button is held down:
			current[0].Down = msg->wParam & MK_LBUTTON;
			// Check if right button down:
			current[1].Down = msg->wParam & MK_RBUTTON;
		}
		break;
		case WM_LBUTTONDOWN: {
			current[0].Down = true;// msg->wParam & MK_LBUTTON;
		 }
		break;
		case WM_LBUTTONUP: {
			current[0].Down = false;// msg->wParam & MK_LBUTTON;
		}
		break;
		case WM_RBUTTONDOWN: {
			current[1].Down = true;// msg->wParam & MK_LBUTTON;
							 }
							 break;
		case WM_RBUTTONUP: {
			current[1].Down = false;// msg->wParam & MK_LBUTTON;
						   }
						   break;
	}

	for (int i = 0; i<current.size(); i++ ) {
		if (current[i].Down!=previous[i].Down) {
			EventData d;
			d.Index = current[i].Index;
			d.Position = current[i].Position;
			if (current[i].Down) {
				Down(d);
			} else {
				Up(d);
			}
		}
	}

	previous = current;
}

#else

void InputManager::Update(void* input) {
    
}

#endif
